require "irb"

class IrbOperation  < Operation

	condition do |context|
		args = context.symbol(:args)
		args.find{|x| x == "--irb"}
	end

	def run(context)
		logger.debug Locale.irb_spawn

		ap_path = nil

		#$0 = File::basename(ap_path, ".rb") if ap_path

		IRB.setup(ap_path)
		irb = IRB::Irb.new

		IRB.instance_eval do
		@CONF[:IRB_RC].call(irb.context) if @CONF[:IRB_RC]
		@CONF[:MAIN_CONTEXT] = irb.context
		end
 
		trap("SIGINT") do
		irb.signal_handle
		end
		    
		catch(:IRB_EXIT) do
		irb.eval_input
		end

	end
end
